package com.carl.zlds.controller.admin;

import com.carl.zlds.tool.common.PageBO;
import com.carl.zlds.tool.common.result.Result;
import com.carl.zlds.controller.BaseController;
import com.carl.zlds.model.GameTagInfo;
import com.carl.zlds.pojo.dto.SaveGameTagInfoDTO;
import com.carl.zlds.service.IGameTagInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author carl
 */
@Slf4j
@RestController(value = "admin.gameTagInfoController")
@RequestMapping("/admin/1/game-tag-info")
@Api(tags = {"管理端 - 游戏标签管理"})
public class GameTagInfoController extends BaseController {

    private final IGameTagInfoService gameTagInfoService;

    @Autowired
    public GameTagInfoController(IGameTagInfoService gameTagInfoService) {
        this.gameTagInfoService = gameTagInfoService;
    }

    @ApiOperation("保存游戏标签")
    @PostMapping(value = "/save")
    public Result<Void> save(@RequestParam(value = "id", defaultValue = "0") Long id,
                             @Valid SaveGameTagInfoDTO dto) {
        gameTagInfoService.saveGameTagInfo(id, dto);
        return Result.success();
    }

    @ApiOperation("删除游戏标签")
    @PostMapping(value = "/delete")
    public Result<Void> delete(@RequestParam("id") Long id) {
        gameTagInfoService.deleteGameTagInfo(id);
        return Result.success();
    }

    @ApiOperation("游戏标签列表")
    @GetMapping(value = "/list")
    public Result<Map<String, Object>> list(@RequestParam(value = "gameTagId", defaultValue = "0") Long gameTagId) {
        List<GameTagInfo> list = gameTagInfoService.getGameTagInfoList(gameTagId, -1L);
        Map<String, Object> map = new HashMap<>(1);
        map.put("list", list);
        return Result.success(map);
    }
}
